package co.sanduche.teach;

import java.util.List;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import co.sanduche.teach.gallery.GalleryDBOpenHelper;
import co.sanduche.teach.gallery.ImageItem;
import co.sanduche.util.EPBaseAdapter;

/**
 * A placeholder fragment containing a simple view.
 */
public class PlaceholderFragment extends Fragment {
	private List<ImageItem> images;
	private GalleryDBOpenHelper dbHelper;

	public PlaceholderFragment() {
		
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_sqlimages,
				container, false);
		ListView lv = (ListView) rootView.findViewById(R.id.listImages);
		dbHelper= new GalleryDBOpenHelper(this.getActivity());
		lv.setAdapter(new EPBaseAdapter(this.getActivity(), R.layout.item_sqlimage) {

			@Override
			public void initView(int position, View view) {
				init();
				ImageItem ii = images.get(position);
				((TextView) view.findViewById(R.id.id)).setText(ii.getId() + "");
				((TextView) view.findViewById(R.id.url)).setText(ii.getUrl()
						+ "");

				((TextView) view.findViewById(R.id.path)).setText(ii
						.getPosted() + "");

				((TextView) view.findViewById(R.id.server_id)).setText(ii
						.getServerId() + "");

				((TextView) view.findViewById(R.id.state)).setText(ii
						.getState() + "");
			}

			private void init() {
				images = dbHelper.loadAllData();
			}

			@Override
			public int getCount() {
				init();
				return images.size();
			}
		});
		return rootView;
	}
}